package com.learnjava.learnjava1.jpa.entity;

import jakarta.persistence.*;
import lombok.*;

import java.util.Set;

@Entity
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "departments")
@ToString(exclude = {"company"})

public class DepartmentEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false, unique = true)
    private Long id;

    @Column(name = "title", nullable = false)
    private String title;

    @Column(name = "is_active", nullable = false)
    private Boolean isActive;

    @Column(name = "parent_department_id", nullable = true)
    private Long parentDepartmentId;

    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "parent_department_id", referencedColumnName = "id")
    private Set<DepartmentEntity> childDepartaments;

    @ManyToOne()
    @JoinColumn(name = "company_id",referencedColumnName = "id")
    private CompanyEntity company;
}
